package com.carbon.system.controller;

import com.carbon.common.api.Paging;
import com.carbon.domain.common.ApiResult;
import com.carbon.system.common.BaseController;
import com.carbon.system.entity.CarbonArticleComment;
import com.carbon.system.param.CarbonArticleCommentQueryParam;
import com.carbon.system.service.CarbonArticleCommentService;
import com.carbon.system.vo.CarbonArticleCommentQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * CarbonArticleComment控制器，负责处理文章评论相关的前端请求。
 */
@Slf4j
@RestController
@RequestMapping("/carbonArticleComment")
@Api(value = "文章评论模块", tags = {"文章评论模块"})
public class CarbonArticleCommentController extends BaseController {

    @Autowired
    private CarbonArticleCommentService carbonArticleCommentService;

    /**
     * 添加文章评论
     *
     * @param carbonArticleComment 待添加的文章评论对象
     * @return 添加结果，成功返回true，失败返回false
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加CarbonArticleComment对象",notes = "添加")
    public ApiResult<Boolean> addCarbonArticleComment(@Valid @RequestBody CarbonArticleComment carbonArticleComment) {
        boolean flag = carbonArticleCommentService.save(carbonArticleComment);
        return ApiResult.result(flag);
    }

    /**
     * 修改文章评论
     *
     * @param carbonArticleComment 待修改的文章评论对象
     * @return 修改结果，成功返回true，失败返回false
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改CarbonArticleComment对象",notes = "修改")
    public ApiResult<Boolean> updateCarbonArticleComment(@Valid @RequestBody CarbonArticleComment carbonArticleComment) {
        boolean flag = carbonArticleCommentService.updateById(carbonArticleComment);
        return ApiResult.result(flag);
    }

    /**
     * 删除文章评论
     *
     * @param id 文章评论的ID
     * @return 删除结果，成功返回true，失败返回false
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除CarbonArticleComment对象",notes = "删除")
    public ApiResult<Boolean> deleteCarbonArticleComment(@PathVariable String id) {
        boolean flag = carbonArticleCommentService.removeById(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取文章评论详情
     *
     * @param id 文章评论的ID
     * @return 文章评论的详细信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取CarbonArticleComment对象详情",notes = "查看")
    public ApiResult<CarbonArticleCommentQueryVo> getCarbonArticleComment(@PathVariable String id) {
        CarbonArticleCommentQueryVo carbonArticleCommentQueryVo = carbonArticleCommentService.getCarbonArticleCommentById(id);
        return ApiResult.ok(carbonArticleCommentQueryVo);
    }

    /**
     * 获取文章评论分页列表
     *
     * @param carbonArticleCommentQueryParam 文章评论的查询参数
     * @return 分页的文章评论列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取CarbonArticleComment分页列表",notes = "分页列表")
    public ApiResult<Paging<CarbonArticleCommentQueryVo>> getCarbonArticleCommentPageList(@Valid @RequestBody(required = false) CarbonArticleCommentQueryParam carbonArticleCommentQueryParam) {
        Paging<CarbonArticleCommentQueryVo> paging = carbonArticleCommentService.getCarbonArticleCommentPageList(carbonArticleCommentQueryParam);
        return ApiResult.ok(paging);
    }

}
